/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package cn.newtest.bi.collection.model;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/** 
 * 指标
 *
 * @author <a href="mailto: guanfeng@risesoft.net">关锋</a>
 * @version $Revision$
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="Rpt_Indication")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class Indication implements Comparable<Object>, Serializable {
	
	private static final long serialVersionUID = -985322961753014729L;

	@Id
	@Column(name="Indication_guid",length=38)
	@GenericGenerator(name="Indication-assigned",strategy="assigned")
	private String guid;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Indicationtype_Guid")
	private IndicationType indicationType;
	
	@Column(name="Indication_code",length=64)
	private String code;
	
	@Column(name="Indication_shortname",length=128)
	private String shortName;
	
	@Column(name="Indication_fullname",length=128)
	private String fullName;
	
	@Basic
	private Double tabIndex;
	
	@Column(name="Indication_measureunit",length=64)
	private String measureUnit;
	
	@Column(name="Indication_Level")
	private Integer level;
	
	/**
	 * 1:采集
	 * 2:汇总
	 * 3:采集加汇总
	 */
	@Column(name="Indication_Usage")
	private Integer usage;
	
	@Column(name="Indication_datatype")
	private Integer dataType;
	
	@Column(name="Indication_datalength")
	private Integer dataLength;
	
	@Column(name="Indication_dataprecision")
	private Integer dataPrecision;
	
	@Column(name="Indication_isEnabled")
	private Boolean enabled;
	
	@Column(name="Indication_isvirtual")
	private Boolean virtual;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Parent_Indication_GUID",nullable=true)
	private Indication parentIndication;
	
	@Transient
	public String getTypeName() {
		if(indicationType != null){
			return indicationType.getName();
		}
		return "";
	}

	@Transient
	public String getParentGuid() {
		if(parentIndication != null){
			return parentIndication.getGuid();
		}
		return "";
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getDataLength() {
		return dataLength;
	}

	public void setDataLength(Integer dataLength) {
		this.dataLength = dataLength;
	}

	public Integer getDataPrecision() {
		return dataPrecision;
	}

	public void setDataPrecision(Integer dataPrecision) {
		this.dataPrecision = dataPrecision;
	}

	public Integer getDataType() {
		return dataType;
	}

	public void setDataType(Integer dataType) {
		this.dataType = dataType;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public IndicationType getIndicationType() {
		return indicationType;
	}

	public void setIndicationType(IndicationType indicationType) {
		this.indicationType = indicationType;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	public Boolean getVirtual() {
		return virtual;
	}

	public void setVirtual(Boolean virtual) {
		this.virtual = virtual;
	}

	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	public String getMeasureUnit() {
		return measureUnit;
	}

	public void setMeasureUnit(String measureUnit) {
		this.measureUnit = measureUnit;
	}

	public Indication getParentIndication() {
		return parentIndication;
	}

	public void setParentIndication(Indication parentIndication) {
		this.parentIndication = parentIndication;
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public Double getTabIndex() {
		return tabIndex;
	}

	public void setTabIndex(Double tabIndex) {
		this.tabIndex = tabIndex;
	}

	public Integer getUsage() {
		return usage;
	}

	public void setUsage(Integer usage) {
		this.usage = usage;
	}

	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		Indication myClass = (Indication) object;
		return new CompareToBuilder().append(this.level, myClass.level).append(this.tabIndex, myClass.tabIndex).append(this.shortName, myClass.shortName).append(this.dataType, myClass.dataType).append(this.dataPrecision, myClass.dataPrecision).append(this.measureUnit, myClass.measureUnit).append(this.code, myClass.code).append(this.virtual, myClass.virtual).append(this.enabled, myClass.enabled).append(this.fullName, myClass.fullName).append(this.usage, myClass.usage).append(this.guid, myClass.guid).append(this.dataLength, myClass.dataLength).toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof Indication)) {
			return false;
		}
		Indication rhs = (Indication) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(this.level, rhs.level).append(this.tabIndex, rhs.tabIndex).append(this.shortName, rhs.shortName).append(this.dataType, rhs.dataType).append(this.dataPrecision,rhs.dataPrecision).append(this.measureUnit, rhs.measureUnit).append(this.code, rhs.code).append(this.virtual, rhs.virtual).append(this.enabled, rhs.enabled).append(this.fullName, rhs.fullName).append(this.usage, rhs.usage).append(this.guid, rhs.guid).append(this.dataLength,rhs.dataLength).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(273066705, 446907567).appendSuper(super.hashCode()).append(this.level).append(this.tabIndex).append(this.shortName).append(this.dataType).append(this.dataPrecision).append(this.measureUnit).append(this.code).append(this.virtual).append(this.enabled).append(this.fullName).append(this.usage).append(this.guid).append(this.dataLength).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("dataLength", this.dataLength).append("usage", this.usage).append("enabled", this.enabled).append("virtual", this.virtual).append("measureUnit", this.measureUnit).append("tabindex", this.tabIndex).append("dataPrecision", this.dataPrecision).append("shortName", this.shortName).append("code", this.code).append("fullName", this.fullName).append("dataType", this.dataType).append("guid", this.guid).append("level", this.level).toString();
	}
}